package com.meichis.yndms.ui.activity;

import android.text.TextUtils;

import androidx.databinding.DataBindingUtil;

import com.meichis.mcsappframework.gesturelockview.CustomLockView;
import com.meichis.yndms.R;
import com.meichis.yndms.databinding.ActivityGestureLockManageBinding;
import com.meichis.yndms.ui.common.BaseActivity;

public class GestureLockManageActivity extends BaseActivity {

    private ActivityGestureLockManageBinding binding;


    @Override
    protected void setDataBindingContentView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_gesture_lock_manage);
        binding.setClick(new ClickEvent());
        binding.setLifecycleOwner(this);
    }

    @Override
    protected void init() {
        binding.navigation.txtTitle.setText("手势密码");
        binding.navigation.navBack.setOnClickListener(v -> onBackPressed());
    }


    @Override
    protected void onResume() {
        super.onResume();
        binding.swGestureLock.setChecked(!TextUtils.isEmpty(util.getStringValue(CustomLockView.getSaveLockKey())));
    }

    public class ClickEvent {

        public void onGestureLock() {
            if (binding.swGestureLock.isChecked()) {
                startActivity(GestureLockActivity.getStateIntent(GestureLockManageActivity.this, CustomLockView.LockMode.SETTING_PASSWORD));
            } else {
                startActivity(GestureLockActivity.getStateIntent(GestureLockManageActivity.this, CustomLockView.LockMode.CLEAR_PASSWORD));
            }
        }

        public void onModify() {
            if (!binding.swGestureLock.isChecked()) {
                showMsg("手势密码未开启");
                return;
            }
            startActivity(GestureLockActivity.getStateIntent(GestureLockManageActivity.this, CustomLockView.LockMode.EDIT_PASSWORD));
        }
    }

}